﻿<UserControl x:Class="RSSFeedReader.Views.ChannelView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:res="clr-namespace:RSSFeedReader.Resources;assembly=RSSFeedReader.Resources"
             xmlns:vm="clr-namespace:RSSFeedReader.ViewModels;assembly=RSSFeedReader.ViewModels"
             xmlns:converter="clr-namespace:RSSFeedReader.Converters"
             xmlns:controls="clr-namespace:RSSFeedReader.Controls;assembly=RSSFeedReader.ViewModels"
             mc:Ignorable="d"
             d:DesignWidth="500"
             d:DesignHeight="500">
    <UserControl.Resources>
        <converter:ChannelTypeEnumConverter x:Key="ChannelTypeConverter" />
        <converter:NewPostsConverter x:Key="NewPostsConverter" />
        <ContextMenu x:Key="ChannelViewContextMenu">
            <MenuItem Header="{x:Static res:Strings.ChannelView_CreateNewFolderMenuItem}"
                      Command="{Binding Path=AddNewFolderCommand}" />
            <MenuItem Header="{x:Static res:Strings.AddNewFeed}"
                      Command="{Binding Path=AddNewFeedCommand}" />
            <Separator />
            <MenuItem Header="{x:Static res:Strings.ChannelView_MarkAllAsReadMenuItem}"
                      Command="{Binding Path=MarkAllAsReadCommand}" />
            <Separator />
            <MenuItem Header="{x:Static res:Strings.ChannelView_SyncFeedMenuItem}"
                      Command="{Binding Path=SyncChannelCommand}"/>
            <MenuItem Header="{x:Static res:Strings.ChannelView_SyncAllFeedsMenuItem}"
                      Command="{Binding Path=SyncAllChannelsCommand}" />
            <MenuItem Header="{x:Static res:Strings.ChannelView_DeleteMenuItem}"
                      Command="{Binding Path=DeleteChannelCommand}" />
            <MenuItem Header="{x:Static res:Strings.ChannelView_RenameMenuItem}"
                      Command="{Binding Path=RenameChannelCommand}"
                      InputGestureText="F2"/>
            <MenuItem Header="{x:Static res:Strings.ChannelView_MoveToFolderMenuItem}"
                      Command="{Binding Path=MoveToFolderCommand}" />
            <Separator />
            <MenuItem Header="{x:Static res:Strings.ChannelView_PropertiesMenuItem}"
                      Command="{Binding Path=ChannelPropertiesCommand}"
                      InputGestureText="Alt+Enter"/>

        </ContextMenu>
        <HierarchicalDataTemplate x:Key="ChannelDataTemplate"
                                  DataType="{x:Type vm:ChannelViewModel}"
                                  ItemsSource="{Binding Children}">
            <Grid Margin="0,2,0,0"
                  ContextMenu="{StaticResource ChannelViewContextMenu}"
                  Width="Auto">
                <Grid.ToolTip>
                    <TextBlock MaxWidth="400"
                               TextWrapping="Wrap"
                               Text="{Binding Path=Description}" />
                </Grid.ToolTip>
                <StackPanel Orientation="Horizontal"
                            Margin="0,0,0,5">
                    <Image x:Name="image"
                           Width="18"
                           Height="18"
                           Source="{Binding Path=ChannelType, Converter={StaticResource ChannelTypeConverter}}"
                           Margin="0,0,3,0" />
                    <TextBlock x:Name="_HeaderTxtBlock"
                               Margin="0,0,5,0"
                               Text="{Binding Path=Title, Mode=TwoWay}"
                               Foreground="#FFFFFFFF">
                    </TextBlock>
                    <TextBlock x:Name="_NewPostsCount"
                               Margin="5,0,0,0"
                               Text="{Binding Path=NewPosts, Mode=TwoWay, Converter={StaticResource NewPostsConverter}}"
                               Foreground="Red">
                    </TextBlock>
                    <TextBlock x:Name="tbLoading"
                               Margin="5,0,0,0"
                               Foreground="Gray">
                            <TextBlock.Style>
                                <Style>
                                    <Setter Property="TextBlock.Text"
                                            Value="{x:Static res:Strings.ChannelView_LoadingFeeds}" />
                                    <Setter Property="TextBlock.Visibility"
                                            Value="Collapsed" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=IsLoading, Mode=TwoWay}"
                                                     Value="True">
                                            <Setter Property="TextBlock.Visibility"
                                                    Value="Visible" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                    </TextBlock>
                </StackPanel>
            </Grid>
            <HierarchicalDataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}, Mode=FindAncestor}}"
                             Value="True">
                    <Setter TargetName="_HeaderTxtBlock"
                            Property="Foreground"
                            Value="#FF767676" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}, Mode=FindAncestor}}"
                             Value="True">
                    <Setter TargetName="_HeaderTxtBlock"
                            Property="Foreground"
                            Value="#FF767676" />
                </DataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}, Mode=FindAncestor}}"
                                   Value="True" />
                        <Condition Binding="{Binding Path=ChannelType}"
                                   Value="Folder" />
                    </MultiDataTrigger.Conditions>
                    <Setter TargetName="image"
                            Property="Source"
                            Value="pack://application:,,,/RSSFeedReader.Resources;component/Images/OpenFolder.png" />
                </MultiDataTrigger>
            </HierarchicalDataTemplate.Triggers>
        </HierarchicalDataTemplate>
    </UserControl.Resources>
    <Grid>
        <controls:MyTreeView x:Name="_MainTree"
                             ItemsSource="{Binding Path=Channels}"
                             ItemsPanel="{DynamicResource FeedViewItemTemplate}"
                             ItemContainerStyle="{DynamicResource TreeViewItemStyle}"
                             ItemTemplate="{StaticResource ChannelDataTemplate}"
                             AllowDrop="True"/>
    </Grid>
</UserControl>
